#include <REGX52.H>
#include <INTRINS.H>

void Delay(unsigned int xms)		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	
	while(xms--)
	{
		i = 2;
		j = 199;
		do
		{
			while (--j);
		} while (--i);
	}

}

void main()
{
	unsigned char ledNum = 0;
	
	P2_7 = 0;					//初始化
	
	while(1)
	{
		
		//按下独立按键 KEY_1 实现LED灯向左移位
		if(P3_1 == 0)
		{
			Delay(10);			//按下延时消抖
			while(P3_1 == 0);	//检测松手，当按键按下没有松开时一直执行循环检测
			Delay(10);			//松手延时消抖
			
			ledNum++;
			if(ledNum >=8)
				ledNum = 0;
			
			P2 = ~(1 << (7 - ledNum));
		}
		
		
		//按下独立按键 KEY_2 实现LED灯向右移位
		if(P3_0 == 0)
		{
			Delay(10);			//按下延时消抖
			while(P3_0 == 0);	//检测松手，当按键按下没有松开时一直执行循环检测
			Delay(10);			//松手延时消抖
			
			if(ledNum == 0)
				ledNum = 8;
			ledNum--;
			
			
			P2 = ~(1 << (7 - ledNum));
		}
	}
}
